/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.geftu.util;

import java.util.Set;
import javax.swing.JOptionPane;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import org.hibernate.HibernateException;

/**
 *
 * @author Nei
 * @param <T>
 */
public class ValidaInsert<T> {

    public static String isvalid(Object o) {
        String retorno = "";
        try {

            ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
            Validator validator = factory.getValidator();
            Set<ConstraintViolation<Object>> constraint = validator.validate(o);
            //retorno = constraint.toString();

            for (ConstraintViolation<Object> error : constraint) {
                System.out.println("Testexxx: " + error.getMessage());
                retorno = error.getMessage();
            }

        } catch (HibernateException e) {
        } finally {

        }

        return retorno;

    }

}
